package com.neuedu.shop.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neuedu.shop.mapper.UserMapper;
import com.neuedu.shop.pojo.Admin;
import com.neuedu.shop.pojo.User;
import com.neuedu.shop.service.UserService;
import com.neuedu.shop.util.Util;

/**
 * @author ZhangHongRui
 *
 *         2019年12月27日
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
	/**
	 * 持有持久层接口的对象
	 */
	@Autowired // 自动注入 dependency injection
	private UserMapper mapper;

	/**
	 * 在业务层中调用持久层中的结果
	 */
	@Override
	public List<User> findAll() {
		return mapper.findAll();
	}

	@Override
	public void insert(User user) {
		mapper.insert(user);
	}

	@Override
	public void delete(Integer id) {
		mapper.delete(id);
	}

	@Override
	public void resetPassword(Integer id) {
		mapper.resetPassword(id);
	}

	@Override
	public User login(String name, String pwd) {
		User user = mapper.findByName(name);
		if (user != null && user.getPassword().equals(Util.getMD5(pwd))) {
			return user;
		}
		return null;
	}

	@Override
	public void update(User user) {
		mapper.update(user);

	}

	@Override
	public void batchDelete(int[] ids) {
		for (int id : ids) {
			mapper.delete(id);
		}
	}

}
